<%@ page import="daoImpl.PostDaoImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Post" %>
<%@ page import="javafx.geometry.Pos" %>
<%@ page import="dao.UserDao" %>
<%@ page import="entity.User" %>
<%@ page import="daoImpl.UserDaoImpl" %>
<%@ page import="dao.PostDao" %>
<%@ page import="com.sun.glass.ui.Size" %><%--
  Created by IntelliJ IDEA.
  User: anzhicheng
  Date: 2017/7/13
  Time: 20:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="utf-8">
<style>
    a{text-decoration:none}
    .container{
        width:600px;
        height:auto;
        border-radius: 3px;
        box-shadow:0px 0px 2px #999999; 
    }
    #userImage{
        margin-top: 20px;
        margin-left: 20px;
    }
    #userName{            
        position: relative;
        top:-20px;
        left: 60px;
        font: normal 13px 微软雅黑 ;
    }
    a:link {color:black;}
    a:visited {color:black;} 
    .passage{
        margin-top: -20px;
        margin-left: 20px;
        width:600px;            
    }
    #passageName{
        position: relative;
        top:18px;
        font: normal 18px 微软雅黑 ;
    }
    #date{
        position: relative;
        float:right;
        top:10px;
        left:-45px;
        font: normal 13px 微软雅黑 ;
    }
    #passageMain{
        position: relative;
        top:5px;
        word-wrap: break-word; 
        word-break: normal; 
        width:560px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        overflow: hidden;
        font: normal 15px 微软雅黑 ;
        
    }
    .media-box{
        position: relative;
        top:0px;
        width: 340px;
        height:120px;
    }
    .image1,.image2,.image3 img{
        width: 110px;
        height: 110px;
        background: black;
    }
    .image1{
        position:relative;
    }
    .image2{
        position:relative;
        top: -110px;
        left:113px;
    }
    .image3{
        position:relative;
        top: -220px;
        left:226px;
    }
    
</style>
</head>

<body>

<%!PostDao postDao = new PostDaoImpl(); %>
<%! List<Post> list = null;%>
<%! String bottom = "";%>
<%
    String need = request.getParameter("need");
    if (need.equals("active")){
        list = postDao.queryAllPostsByUsername((String)request.getSession().getAttribute("username"));
        bottom = "loadMyActPages(this)";
    }else if (need.equals("collection")){
        list = postDao.queryAllCollectionsByUsername((String)request.getSession().getAttribute("username"));
        bottom = "loadMyCol(this)";
    }else if (need.equals("allpost")){
        if (request.getParameter("category")!=null){
            request.getSession().setAttribute("category",request.getParameter("category"));
        }
        list = postDao.queryAllPostByCategory((String) request.getSession().getAttribute("category"));
        bottom = "showAtRight(this)";
    }

%>
<%! int pages = 1;%>
<% int maxsize = list.size();
    if (maxsize % 2 == 0){
        pages = maxsize / 2;
    }else {
        pages = maxsize / 2 + 1;
    }
%>
<%
    int targetPage;
    if ((request.getParameter("targetPage")!=null)&&(request.getParameter("targetPage").matches("[0-9]+"))){
        targetPage = Integer.parseInt(request.getParameter("targetPage"));
    }
    else {
        targetPage = 1;
    }
    int begin = 2*(targetPage-1);
%>

<%for (int i = begin;(i<begin + 2)&&(i<maxsize);i++){%>
    <div class="container">
        <div class="user-image">
            <a href=""><img src="img/logologin.png" id="userImage" alt="" width="30" height="30" ></a>
        </div>
        <div class="user-name">
            <a id="userName" href=""></a>
        </div>
        <div class="passage">
            <a href=""  id="passageName"><%=list.get(i).getTitle()%><%System.out.println(list.get(i).getTitle()); %></a>
            <p id="date"><%=list.get(i).getTime()%></p>
            <a href="" ><p id="passageMain">
                <%=list.get(i).getContent()%>
            </p></a>
            <%--<div class="media-box">--%>
                <%--<div class=image1><img src="" ></div>--%>
                <%--<div class=image2><img src="" ></div>--%>
                <%--<div class=image3><img src="" ></div>--%>
            <%--</div>--%>
        </div>
    </div>
<%}%>
<div>
<%
    if (pages!=1){
        for (int i = 0;i<pages;i++){
            int b = i+1;%>
            <input type="button"  value=<%=b%> class="centerBtn" onclick=<%=bottom%>>
        <%}
    }
%>
</div>
</body>
</html>